package io.xxx.mario.room;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.xxx.mario.room.api.JoinRoomRequest;
import io.xxx.mario.room.api.LeaveRoomRequest;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Room", description = "群管理")
@RestController
@RequestMapping("/room")
public class RoomController {

    @Resource
    private RoomService roomService;

    @Resource
    private RoomMapper roomMapper;

    @Operation(summary = "分页查询群列表")
    @GetMapping("/page")
    public Page<Room> getPage(@PageableDefault Pageable pageable,
                              @RequestParam(required = false) String name) {
        return roomService.getPage(pageable, name);
    }

    @Operation(summary = "获取群信息")
    @GetMapping("/{id}")
    public Room get(@PathVariable Long id) {
        return roomMapper.selectById(id);
    }

    @Operation(summary = "入群")
    @PostMapping("/join")
    public void joinRoom(@RequestBody JoinRoomRequest request) {
        roomService.joinRoom(request);
    }

    @Operation(summary = "退群")
    @PostMapping("/leave")
    public void leaveRoom(@RequestBody LeaveRoomRequest request) {
        roomService.leaveRoom(request);
    }
}
